﻿Public Class RposibleCliente

    Public Shared Function SeleccionarTodo(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean) As List(Of EposibleCliente)
        Dim posibleclientes As List(Of EposibleCliente) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                posibleclientes = DposibleCliente.SeleccionarTodo(descEmpresa)
                If posibleclientes Is Nothing Then posibleclientes = New List(Of EposibleCliente)
                If DisplaySelect Then posibleclientes.Insert(0, New EposibleCliente("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return posibleclientes
    End Function
    Public Shared Function Filtra_NombreApePaternoApeMaterno(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal filtro As String) As List(Of EposibleCliente)
        Dim posibleclientes As List(Of EposibleCliente) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                posibleclientes = DposibleCliente.Filtra_NombreApePaternoApeMaterno(descEmpresa, filtro)
                If posibleclientes Is Nothing Then posibleclientes = New List(Of EposibleCliente)
                If DisplaySelect Then posibleclientes.Insert(0, New EposibleCliente("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return posibleclientes
    End Function
    'Public Shared Function SeleccionarFiltroAtencionPosClientexNombreApePaternoApeMaterno _
    '(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal filtro As String, ByVal pVendedor As Evendedor) As List(Of EposibleCliente)
    '    Dim atencionPosClientes As List(Of EposibleCliente) = Nothing

    '    Dim options As New TransactionOptions
    '    options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
    '    options.Timeout = New TimeSpan(0, 2, 0)

    '    Using scope As New TransactionScope(TransactionScopeOption.Required, options)
    '        Try
    '            atencionPosClientes = DposibleCliente.SeleccionarFiltroAtencionPosClientexNombreApePaternoApeMaterno(descEmpresa, filtro, pVendedor)
    '            If atencionPosClientes Is Nothing Then atencionPosClientes = New List(Of EposibleCliente)
    '            If DisplaySelect Then atencionPosClientes.Insert(0, New EposibleCliente("00", "-- SELECCIONAR --"))
    '            scope.Complete()
    '        Catch ex As Exception
    '            Throw
    '        End Try
    '    End Using

    '    Return atencionPosClientes
    'End Function
    Public Shared Function SeleccionarFiltroAtencionPosClientexNombreApePaternoApeMaterno _
    (ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal pProformaCabecera As EproformaCabecera) As List(Of EposibleCliente)
        Dim atencionPosClientes As List(Of EposibleCliente) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                atencionPosClientes = DposibleCliente.SeleccionarFiltroAtencionPosClientexNombreApePaternoApeMaterno(descEmpresa, pProformaCabecera)
                If atencionPosClientes Is Nothing Then atencionPosClientes = New List(Of EposibleCliente)
                If DisplaySelect Then atencionPosClientes.Insert(0, New EposibleCliente("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return atencionPosClientes
    End Function
    Public Shared Function SeleccionarXId(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal idPosCliente As Int32) As List(Of EposibleCliente)
        Dim posibleClientes As List(Of EposibleCliente) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                posibleClientes = DposibleCliente.SeleccionarXId(descEmpresa, idPosCliente)
                If posibleClientes Is Nothing Then posibleClientes = New List(Of EposibleCliente)
                If DisplaySelect Then posibleClientes.Insert(0, New EposibleCliente("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return posibleClientes
    End Function
    Public Shared Function Añadir(ByVal descEmpresa As String, ByVal pPosCliente As EposibleCliente, ByRef idPosCliente As Integer) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = DposibleCliente.Añadir(descEmpresa, pPosCliente, idPosCliente)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function
    Public Shared Function Añadir(ByVal descEmpresa As String, ByVal pPosCliente As EposibleCliente) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = DposibleCliente.Añadir(descEmpresa, pPosCliente)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function
    'Public Shared Function AñadirPosClienteProforma(ByVal pPosCliente As EposibleCliente, ByVal idPosCliente As Int32) As Boolean
    '    Dim resultado As Boolean = False

    '    Dim options As New TransactionOptions
    '    options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
    '    options.Timeout = New TimeSpan(0, 2, 0)

    '    Using scope As New TransactionScope(TransactionScopeOption.Required, options)
    '        Try
    '            resultado = DposibleCliente.Añadir(pPosCliente)
    '            scope.Complete()
    '        Catch ex As Exception
    '            Throw
    '        End Try
    '    End Using

    '    Return resultado
    'End Function
    Public Shared Function Editar(ByVal descEmpresa As String, ByVal cliente As EposibleCliente) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = DposibleCliente.Editar(descEmpresa, cliente)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function
    Public Shared Function Eliminar(ByVal descEmpresa As String, ByVal cliente As EposibleCliente) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = DposibleCliente.Eliminar(descEmpresa, cliente)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function

    '-------    MENU REPORTE EVOLTA / VERSUS    ------------'
    Public Shared Function SeleccionarFiltroAtencionPosClientexNombreApePaternoApeMaternoXVersus _
    (ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal pProformaCabecera As EproformaCabecera) As List(Of EposibleCliente)
        Dim atencionPosClientes As List(Of EposibleCliente) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                atencionPosClientes = DposibleCliente.SeleccionarFiltroAtencionPosClientexNombreApePaternoApeMaternoXVersus(descEmpresa, pProformaCabecera)
                If atencionPosClientes Is Nothing Then atencionPosClientes = New List(Of EposibleCliente)
                If DisplaySelect Then atencionPosClientes.Insert(0, New EposibleCliente("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return atencionPosClientes
    End Function

    Public Shared Function SeleccionarTodoMantenedor(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean) As List(Of EposibleCliente)
        Dim posibleclientes As List(Of EposibleCliente) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                posibleclientes = DposibleCliente.SeleccionarTodoMantenedor(descEmpresa)
                If posibleclientes Is Nothing Then posibleclientes = New List(Of EposibleCliente)
                If DisplaySelect Then posibleclientes.Insert(0, New EposibleCliente("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return posibleclientes
    End Function
    Public Shared Function AñadirMantenedor(ByVal descEmpresa As String, ByVal pPosCliente As EposibleCliente) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = DposibleCliente.AñadirMantenedor(descEmpresa, pPosCliente)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function
    Public Shared Function EditarMantenedor(ByVal descEmpresa As String, ByVal pPosCliente As EposibleCliente) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = DposibleCliente.EditarMantenedor(descEmpresa, pPosCliente)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function
    Public Shared Function EliminarMantenedor(ByVal descEmpresa As String, ByVal pPosCliente As EposibleCliente) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = DposibleCliente.EliminarMantenedor(descEmpresa, pPosCliente)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function
    Public Shared Function BuscarMantenedor(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal pPosCliente As EposibleCliente) As List(Of EposibleCliente)
        Dim posibleclientes As List(Of EposibleCliente) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                posibleclientes = DposibleCliente.BuscarMantenedor(descEmpresa, pPosCliente)
                If posibleclientes Is Nothing Then posibleclientes = New List(Of EposibleCliente)
                If DisplaySelect Then posibleclientes.Insert(0, New EposibleCliente("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return posibleclientes
    End Function

    Public Shared Function SeleccionarTodoXId(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal idPosCliente As Int32) As List(Of EposibleCliente)
        Dim posibleclientes As List(Of EposibleCliente) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                posibleclientes = DposibleCliente.SeleccionarTodoXId(descEmpresa, idPosCliente)
                If posibleclientes Is Nothing Then posibleclientes = New List(Of EposibleCliente)
                If DisplaySelect Then posibleclientes.Insert(0, New EposibleCliente("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return posibleclientes
    End Function

End Class
